<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>添加印章</title>
    <link rel="stylesheet" href="/asset/layui/css/layui.css">
    <link rel="stylesheet" href="/asset/css/index.css">
    <link rel="Shortcut Icon" href="cachet.ico">
    <script type="text/javascript" src="/asset/js/jquery-3.3.1.min.js"></script>
	<script src="/asset/layui/layui.js"></script>
    <script src="/asset/js/common.js"></script>
</head>
<body >
<div class="alert_bigbox">

	<form class="layui-form">
		  <input type="hidden" name="model" id="model" value="${devicesModel.model}">
          <div class="layui-form-item">
              <label for="devicesId" class="layui-form-label">
                  型号编号
              </label>
              <div class="layui-form-mid">
                  ${devicesModel.model}
              </div>
          </div>
          
          <div class="layui-form-item">
              <label for="model" class="layui-form-label">
                  支持网络
              </label>
              <div class="layui-form-mid">
              	${devicesModel.network}
			  </div>
          </div>
          
          <div class="layui-form-item">
              <label for="model" class="layui-form-label">
                  当前版本
              </label>
              <div class="layui-form-mid">
              	${devicesModel.version}
			  </div>
          </div>
          <#assign max=3>
          <div class="layui-form-item">
              <label for="model" class="layui-form-label">
                  升级版本
              </label>
              
             	<div class="layui-form-mid">V</div>
                <div class="layui-input-inline" style="width:60px">
	              	<select name="versionBase">
	              		<#list 0..10 as i>    
				        <option value="${i}" <#if devicesModel.versionBase ==i>selected</#if> >${i}</option>
				        </#list>
			        </select>
		        </div>
		        <div class="layui-form-mid">.</div>
		       <div class="layui-input-inline" style="width:60px">
              	<select name="versionAlpha">
              		<#list 0..10 as i>    
			        <option value="${i}" <#if devicesModel.versionAlpha ==i>selected</#if> >${i}</option>
			        </#list>
			       
		        </select>
		        </div>
		        <div class="layui-form-mid">.</div>
		       <div class="layui-input-inline" style="width:60px">
              	<select name="versionBeta">
              		<#list 0..10 as i> 
			        <option value="${i}" <#if devicesModel.versionBeta ==i>selected</#if> >${i}</option>
			        </#list>
		        </select>
		        </div>
			  
          </div>
          
          <div class="layui-form-item">
              <label for="model" class="layui-form-label">
                  新版固件
              </label>
              <div class="layui-input-inline">
              		<input type="text" name="drivePath" id="drivePath" value="" placeholder="请选择.bin格式的固件" class="layui-input" readonly>
              	
			  </div>
			  <button type="button" class="layui-btn" id="upload">选择固件</button>
          </div>
          
          <div class="layui-form-item">
              <label for="L_repass" class="layui-form-label">
              </label>
              <button  class="layui-btn" lay-filter="add" lay-submit="">增加</button>
          </div>
      </form>

</div>

    <script>
        layui.use(['form','layer','laydate','upload'], function(){
            $ = layui.jquery;
          var form = layui.form,layer = layui.layer,laydate = layui.laydate,upload=layui.upload;
          
          laydate.render({
		    elem: '.dateinput' //指定元素
		  });
        
          //固件上传
		  var uploadInst = upload.render({
		    elem: '#upload'
		    ,exts:'bin'
		    ,url: '/admin/upload/fileupload.htm?module=upgrade'
		    ,done: function(res){
		      if(res.code == 1){
		         $("#drivePath").val(res.data.filepath)
		         layer.msg(res.msg);
		         
		      }else{
		      	layer.msg(res.msg);
		      }
		     
		    }
		    ,error: function(){
		    }
		  });
         

          //监听提交
          form.on('submit(add)', function(data){
          	
          	var arr = new Array();
          	$("input[name='network']:checked").each(function(i){
          		arr[i] = $(this).val();
          	})
          	data.field.network = arr.join(",");
          	
            $.ajax({
      			type:"POST", 
      			url:"/admin/model/publish.htm",
      			data:data.field,
      			success:function(result) {
		      
		      		if(result.code=='1'){
		      			layer.alert("增加成功", {icon: 6},function () {
			                // 获得frame索引
			                 window.parent.location.reload();
			                var index = parent.layer.getFrameIndex(window.name);
			                //关闭当前frame
			                parent.layer.close(index);
			            });
		      		}else{
		      		 	layer.msg(result.msg);
		      		}
		      
		    	 	} 
		    }); 
            
            return false;
          });
          
        });
    </script>

</body>
</html>